﻿using System.Net;
using System.Net.Mail;

namespace YookingBizYQ.Class.Public
{
    public class clsEmail
    {
        // smtpServer SMTP服务器地址 username 发送人邮箱 password 发送人邮箱密码  to 接收人邮箱  subject 邮件主题   body 邮件正文
        public static void SendEmail(string smtpServer, string username, string password, string to, string subject, string body)
        {
            // 设置SMTP服务器端口
            int port = 587;

            // 创建邮件消息
            MailMessage message = new MailMessage(
                from: new MailAddress(username, "Your Name"),
                to: new MailAddress(to));
            message.Subject = subject;
            message.Body = body;

            // 设置SMTP客户端
            using (SmtpClient client = new SmtpClient(smtpServer, port))
            {
                client.Credentials = new NetworkCredential(username, password);
                client.EnableSsl = true; // 如果SMTP服务器需要安全连接，则启用

                // 发送邮件
                client.Send(message);
            }
        }
    }
}
